package app.caretrack.dao;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

public abstract class BaseDao {

    protected EntityManagerFactory emf;
    protected EntityManager em;

    public BaseDao() {
        this.emf = Persistence.createEntityManagerFactory("derby_embedded");
        this.em = this.emf.createEntityManager();
        System.out.println(this.em);
    }

    public <T> T findById(Class<T> cls, Object id) {
        return this.em.find(cls, id);
    }

    public void persist(Object model) {
        this.em.getTransaction().begin();
        this.em.persist(model);
        this.em.getTransaction().commit();
    }

    public void insert() {

    }

    public void delete() {

    }

    public void update() {

    }
}
